namespace Launcher.Ui

import System
import System.ComponentModel
import System.Drawing
import System.Windows.Forms

callable PainterCallable(g as Graphics, canvas as object)

class CircularButton:
"""Description of CircularButton"""

#region events

	event Click as MouseEventHandler
	event VisibleChanged as EventHandler
	
	protected virtual def OnVisibleChanged(e as EventArgs):
		VisibleChanged(self, e)
	
	event SelectedChanged as EventHandler
	
	protected virtual def OnSelectedChanged(e as EventArgs):
		SelectedChanged(self, e)

#endregion

	Selected:
		get:
			return _selected
		set:
			old = _selected
			_selected = value
			if old != _selected: OnSelectedChanged(EventArgs.Empty)

	_selected as bool
		
	Visible:
		get:
			return _visible
		set:
			old = _visible
			_visible = value
			if old != _visible: OnVisibleChanged(EventArgs.Empty)

	_visible = true

	[property(Painter)]
	_painter as PainterCallable
	
	[property(Location)]
	_location = Drawing.Point()
	
	[property(Size)]
	_size = Drawing.Size()

	def constructor():
		pass

	private def Paint(sender as object, e as System.Windows.Forms.PaintEventArgs):
		return unless _visible
		b = System.Drawing.SolidBrush(Constants.ControlColor)
		e.Graphics.FillEllipse(b, Location.X, Location.Y, Size.Width, Size.Height)
		if _painter: _painter(e.Graphics, self)

	def Contains(x as int, y as int):
		radius = Size.Width / 2
		
		dx = Math.Abs(x - Location.X - radius)
		dy = Math.Abs(y - Location.Y - radius)
		
		return Math.Sqrt(dx*dx + dy*dy) <= radius

	def OnClick(e as MouseEventArgs):
		Click(self, e)
